<script>
	$(function(){
		$("#bindcate").click(function(){
			var ret ='' ;
			$(".chpro").each(function(){
                if ($(this).attr('checked')) {
                    var a = $(this).val();
                    ret += a + ',';
                }
            });
			
	    	ret = ret.substring(0, ret.length - 1);
	        if (ret == '') {
				alertMsg.error('请先勾选商品!');
	            return false;
	        }else{		
			    var url =  "{:U('Content/selectcate')}&chpro="+ret;
				$.pdialog.open(url,'Content_selectcate','批量修改分类','{mask:true,width: 800, height: 990}');
			}						
		});
	});
</script>

<form id="pagerForm" method="post" action="{:U($module_name.'/'.$action_name)}" onsubmit="return divSearch(this, 'jbsxBox');">
	<input type="hidden" name="pageNum" value="{$pageNum}" />
	<input type="hidden" name="numPerPage" value="{$numPerPage}" />
	<input type="hidden" name="orderField" value="{$orderField}" />
	<input type="hidden" name="orderDirection" value="{$orderDirection}" />
	<input type="hidden" name="keywords" value="{$keywords}" />
	<input type="hidden" name="sfield" value="{$sfield}" />
	<input type="hidden" name="cid" value="{$catid}" />
	<input type="hidden" name="status" value="{$status_}" />
</form>

<div class="pageHeader">
	<form rel="pagerForm" onsubmit="return divSearch(this, 'jbsxBox');" action="{:U($module_name.'/'.$action_name)}" method="post">
		<input type="hidden" name="m" value="{$module_name}" />
		<input type="hidden" name="a" value="{$action_name}" />
		<input type="hidden" name="cid" value="{$catid}" />
	<div class="searchBar">
		<ul class="searchContent">
			<li style="width:220px;">
				<label style="width:60px;">关键字：</label>
                <input type="text" name="keywords" value="{$keywords}" style="width: 120px;"/>				
				<!--<input type="text" class="autoinput" name="keywords.name" value="{$keywords}" style="width:120px;" postField="keywords" suggestFields="id,name" suggestUrl="{:U('Content/suggest',array('tn'=>'Product','fn'=>'id,name','field'=>'id,name','where'=>myencode(array('category_tag_id'=>$catid),1)))}" lookupGroup="keywords"/>-->
			</li>
			<li style="width:60px;">
			<select name="sfield" class="combox">
				<option value="all" {if $wherefields=='all'}selected="selected"{/if}>全部</option>
				<option value="name" {if $wherefields=='name'}selected="selected"{/if}>产品名称</option>
				<option value="id" {if $wherefields=='id'}selected="selected"{/if}>ID</option>
				<option value="code" {if $wherefields=='code'}selected="selected"{/if}>编号</option>
			</select>	
			<input type="hidden" name="sfield_name" value="p.id,pd.name,p.code" />
			</li>
			
				<li style="width:100px;">
				
				<select name="brand" class="combox">
					<option value="">全部品牌</option>
					<volist name='brand' id='b'>
					<option value="{$b['id']}" {if $where['brand_id']===$b['id']}selected="selected"{/if}>{$b.name}</option>
					</volist>
				</select>
			</li>
			<li style="width:60px;">
				<select name="status" class="combox">
					<option value="ALL">全部状态</option>
					<option value="0" {if $where['status']==='0'}selected="selected"{/if}>已下架</option>
					<option value="1" {if $where['status']==='1'}selected="selected"{/if}>已上架</option>
				</select>
			</li>
			<div class="buttonActive"><div class="buttonContent"><button type="submit">检索</button></div></div>
		</ul>
	</div>
	</form>
</div>
<div class="pageContent">
	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="add" href="{:U($module_name.'/add',array('cid'=>$catid))}" rel='pro_add' target="navTab"  ><span>添加产品</span></a></li>
		  
			<li><a class="edit" href="{:U('Content/add',array('catid'=>$catid))}" target="navTab" rel="ids[]" warn="请选择一条记录"><span>修改信息</span></a></li>
			<li><a target="selectedTodo" rel="ids[]" href="{:U('Content/attribute_s',array('ftodo'=>'insert'))}" class="add"><span>添加属性</span></a></li>
			<li><a target="selectedTodo" rel="ids[]" href="{:U('Content/attribute_s',array('ftodo'=>'delete'))}" class="delete"><span>删除属性</span></a>
			<a href="{:U('Content/attribute_s',array('todo'=>'adddel'))}" target="navTab" id="forstautss" style="display:none;">添加/删除属性</a></li>	<!---->
			<li><a target="selectedTodo" rel="ids[]" href="{:U('Content/editcate',array('ftodo'=>'childcate'))}" class="add"><span>修改附属分类</span></a>
			<li><a target="selectedTodo" rel="ids[]" href="{:U('Content/editcate',array('ftodo'=>'miancate'))}" class="add"><span>修改主分类</span></a>
			<a title="此操作只移出附属分类，不会移出主分类，要继续操作吗？" target="selectedTodo" rel="ids[]" href="{:U('Content/removecate',array('cate'=>$catid))}" class="delete"><span>移出分类</span></a>
			<!--<li><a id = "bindcate" rel='Content_selectcate' ><span>修改分类</span></a></li>-->
			<!--<li><a id = "bindcate_bak" target="dialog" width="880" height="650"  rel='bindcate' href='Content/selectcate' ><span>批量修改分类</span></a></li>	-->
			<!--<li><a id = "bindattr" href="{:U('Content/selectattr')}"  target="navTab"  ><span>批量修改属性</span></a></li>-->
			<li><a title="确实要下架这些产品吗?" target="selectedTodo" rel="ids[]" href="{:U('Content/status',array('status'=>'0'))}" class="edit"><span>批量下架</span></a></li>
			<li><a title="确实要上架这些产品吗?" target="selectedTodo" rel="ids[]" href="{:U('Content/status',array('status'=>'1'))}" class="edit"><span>批量上架</span></a></li>
			<li><a class="icon" href="javascript:$.printBox('order_list')"><span>打印</span></a></li>
			<li><a target="selectedTodo" rel="ids[]" href="{:U('Sales/procoupon_edit',array('ftodo'=>'insert'))}" class="add"><span>添加优惠券</span></a>
			<a href="{:U('Sales/procoupon_edit',array('todo'=>addcoupon))}" target="dialog" id="procoupon" style="display:none;">添加优惠券</a>
			<a href="{:U('Content/attribute_s',array('todo'=>'adddel'))}" target="dialog" id="forstautss2" style="display:none;">.</a></li>
		</ul>
	</div>
	
	<div class="panelBar">
		<ul class="toolBar">
			<li><a target="selectedTodo" rel="ids[]" href="{:U('Product/mname',array('ftodo'=>'view'))}" class="add"><span>批量修改模板</span></a></li>
		</ul>
	</div>
	<div id="order_list">
		<table class="list" width="98%" rel="jbsxBox" layoutH="155">
		<thead>
			<tr>
				<th width="22"><input type="checkbox" group="ids[]" class="checkboxCtrl"></th>
				<th width="60" orderField="id" {if $orderField=='id'}class="{$orderDirection}"{/if}>ID</th>
				<th width="80" orderField="code" {if $orderField=='code'}class="{$orderDirection}"{/if}>编号</th>
				<th orderField="name" {if $orderField=='name'}class="{$orderDirection}"{/if}>标题</th>
				<th width="150" orderField="mian_cat" {if $orderField=='mian_cat'}class="{$orderDirection}"{/if}>分类</th>
				<th width="120" orderField="create_date" {if $orderField=='create_date'}class="{$orderDirection}"{/if}>创建时间</th>
				<th width="120" orderField="create_date" {if $orderField=='create_date'}class="{$orderDirection}"{/if}>更新时间</th>
				<th width="30" orderField="status" {if $orderField=='status'}class="{$orderDirection}"{/if}>状态</th>
				<th width="80">操作</th>
				<th width="80">促销操作</th>
			</tr>
		</thead>
		<tbody>
{if $list}
<volist name="list" id="vo">
			<tr target="sid_dv" rel="{$vo['id']}">
				<td><input name="ids[]" class="chpro" value="{$vo['id']}" type="checkbox"></td>
				<td>{$vo['id']}</td>
				<td>{$vo['code']}</td>
				<td><a title="查看{$desc[$vo['id']]['name']}" target="dialog" width="880" height="650" rel="Content_show_{$vo['id']}" href="{:U('Content/show',array('id'=>$vo['id']))}">{$vo['name']}
				
				</a>
				
				<br/>
				<volist name='vo.attr' id='a'>{if $a['value']}[{$a.value}]&nbsp;&nbsp;{/if}</volist>
				</td>

				<td>
					<volist name='vo.cat' id='c'>{if $c['name']}[{$c.name}]&nbsp;&nbsp;{/if}</volist>
					<!--{$status[$vo['status']]}-->
				</td>
				
				<td>{if $vo['create_date']=='0'}-{else}{$vo['create_date']|date="Y-m-d H:i:s",###}{/if}</td>
				<td>{if $vo['write_date']=='0'}-{else}{$vo['write_date']|date="Y-m-d H:i:s",###}{/if}</td>
				<td>
					{if $vo['status']==0}
					<a title="将商品设置为上架" target="ajaxTodo" rel="jbsxBox" href="{:U('Content/status',array('id'=>$vo['id'],'status'=>'1'))}" class="btnxj">上下架</a>
					{else}
					<a title="将商品设置为下架" target="ajaxTodo" rel="jbsxBox" href="{:U('Content/status',array('id'=>$vo['id'],'status'=>'0'))}" class="btnsj">上下架</a>
					{/if}
					<!--{$status[$vo['status']]}-->
				</td>
				<td>
					<a title="查看{$desc[$vo['id']]['name']}" target="dialog" width="880" height="650" rel="Content_show_{$vo['id']}" href="{:U('Content/show',array('id'=>$vo['id']))}" class="btnLook">查看</a>
					<a title="编辑{$desc[$vo['id']]['name']}"   target="navTab" href="{:U('Content/add',array('id'=>$vo['id'],'catid'=>$catid))}" rel='pro_add' class="btnEdit">编辑</a>
					
					
				</td>
				<td>
						{if $vo['status'] == 1}
							{if $coupon['sale'][$vo['id']] && $coupon['sale'][$vo['id']]['enable']==1}
							<a class="btnjhs" title='巨划算商品'>巨</a>
							{else}
							<a class="btnjhs2" href="{:U('Sales/edit',array('proid'=>$vo['id'],'cid'=>$catid,'listkey'=>'ju'))}" target="dialog" width="800" height="550" title="添加巨划算">添加巨划算</a>																	
							{/if}
							{if $coupon['big'][$vo['id']] && $coupon['big'][$vo['id']]['enable']==1}
							<a class="btndzpf" title='大宗批发商品'>大宗批发</a>
							{else}
							<a class="btndzpf2" href="{:U('Sales/package_edit',array('proid'=>$vo['id'],'type'=>'BIG'))}"  target="dialog" width="600" height="550" title="添加大宗批发">添加大宗批发</a>
							{/if}
							<a class="btntj" href="{:U('Sales/package_index',array('selproid'=>$vo['id'],'type'=>'SERIES'))}" rel='22' target="dialog" width="1000" height="400" title="选择套餐">选择套餐</a>
						{/if}
				</td>
			</tr>
</volist>
{else}
			<tr><td colspan="7" height="35" align="center">暂无相关产品</td></tr>
{/if}
		</tbody>
	</table>
	</div>
<div class="panelBar">
	<div class="pages">
		<span>显示</span>
		<select class="combox" name="numPerPage" onchange="navTabPageBreak({numPerPage:this.value},'jbsxBox')">
			<option value="20" {if $numPerPage==20}selected="selected"{/if}>20</option>
			<option value="50" {if $numPerPage==50}selected="selected"{/if}>50</option>
			<option value="66" {if $numPerPage==66}selected="selected"{/if}>66</option>
			<option value="100" {if $numPerPage==100}selected="selected"{/if}>100</option>
			<option value="200" {if $numPerPage==200}selected="selected"{/if}>200</option>
			<option value="500" {if $numPerPage==500}selected="selected"{/if}>500</option>
		</select>
		<span>条，共{$totalCount}条</span>
	</div>
	
	<div class="pagination" targetType="navTab" rel="jbsxBox" totalCount="{$totalCount}" numPerPage="{$numPerPage}" pageNumShown="10" currentPage="{$pageNum}"></div>
</div>
</div>
<script>
function ajaxTodo(url){
	$.ajax({
		type: 'POST',
		url: url,
		dataType: "json",
		cache: false,
		success: function(){ $("a", $(".j-num")).parent('.selected').children().click();return 0; },
		error: DWZ.ajaxError
	});
}

if(typeof('showFace')!="function"){
function navTabAjaxDone(json){
    if (json.action == 'attribute_s'){
		var url = "{:U('Content/attribute_s',array('todo'=>'adddel'))}" + '&ids='+json.ids +'&ftodo='+json.ftodo;
		$("#forstautss").attr('href',url);
        $("#forstautss").click();
    }else if(json.action == 'procoupon_edit'){
		var url = "{:U('Sales/procoupon_edit',array('todo'=>'addcoupon'))}" + '&ids='+json.ids +'&ftodo='+json.ftodo;
		$("#procoupon").attr('href',url);
        $("#procoupon").click();
	}else if(json.action == 'editcate'){
		var url = "{:U('Content/editcate',array('todo'=>'addcate'))}" + '&ids='+json.ids +'&ftodo='+json.ftodo;
		$("#procoupon").attr('href',url);
		$("#procoupon").attr('rel','editcate');
        $("#procoupon").click();
	}else if(json.action == 'upmanme'){
		var url = "{:U('Product/mname',array('ftodo'=>'edit'))}" + '&ids='+json.ids +'&ftodo='+json.ftodo;
		$("#forstautss2").attr('href',url);
        $("#forstautss2").click();
	} else {
		DWZ.ajaxDone(json);
		navTab.reload();
	}
}

}
</script>
